define(["jquery", "easy-admin", "vue"], function ($, ea, Vue) {

    var form    = layui.form,
        element = layui.element;
    return {
        index: function () {
            var app = new Vue({
                el     : '#app',
                data   : {
                    configTabList: [],
                    topTabIndex  : 0,

                    configTabId: 0,
                    configList : [],

                    loading: false
                },
                created: function () {
                    this.getConfigTab();
                },
                mounted: function () {
                    // form.render();
                    ea.listen();
                },
                methods: {
                    getConfigTab() {
                        ea.request.get({
                            url: 'basicHeader'
                        }, (res) => {
                            this.configTabList = res.data;
                            this.configTabId = this.configTabList[0]['children'][0]['id'];
                            this.getConfig();
                        })
                    },
                    getConfig() {
                        ea.request.get({
                            url : 'basicsConfigList',
                            data: {
                                tab_id: this.configTabId
                            },
                            isLoading: false
                        }, (res) => {
                            this.configList = res.data;

                            this.$nextTick(() => {
                                ea.api.upload();
                                form.render();

                                this.loading = true;
                            });
                        })
                    },
                    topTabChange(topTabIndex) {
                        if (this.topTabIndex === topTabIndex) {
                            return;
                        }
                        this.configList = [];
                        this.loading = false;
                        this.topTabIndex = topTabIndex;
                        this.configTabId = this.configTabList[topTabIndex]['children'][0]['id'];
                        this.getConfig();
                    },
                    configTabChange(tabId) {
                        this.configList = [];
                        if (this.configTabId === tabId) {
                            return;
                        }
                        this.loading = false;
                        this.configTabId = tabId;
                        this.getConfig();
                    }
                },
                updated: function () {
                }
            });
        }
    };
});